<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />

  <title>Module: Mongoid::Autoinc</title>

  <link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />

  <script src="../js/jquery.js" type="text/javascript" charset="utf-8"></script>
  <script src="../js/thickbox-compressed.js" type="text/javascript" charset="utf-8"></script>
  <script src="../js/quicksearch.js" type="text/javascript" charset="utf-8"></script>
  <script src="../js/darkfish.js" type="text/javascript" charset="utf-8"></script>

</head>
<body id="top" class="module">

  <div id="metadata">
    <div id="home-metadata">
      <div id="home-section" class="section">
        <h3 class="section-header">
          <a href="../index.html">Home</a>
          <a href="../index.html#classes">Classes</a>
          <a href="../index.html#methods">Methods</a>
        </h3>
      </div>
    </div>

    <div id="file-metadata">
      <div id="file-list-section" class="section">
        <h3 class="section-header">In Files</h3>
        <div class="section-body">
          <ul>
          
            <li><a href="../lib/autoinc/version_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
              class="thickbox" title="lib/autoinc/version.rb">lib/autoinc/version.rb</a></li>
          
            <li><a href="../lib/autoinc/incrementor_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
              class="thickbox" title="lib/autoinc/incrementor.rb">lib/autoinc/incrementor.rb</a></li>
          
            <li><a href="../lib/autoinc_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
              class="thickbox" title="lib/autoinc.rb">lib/autoinc.rb</a></li>
          
          </ul>
        </div>
      </div>

      
    </div>

    <div id="class-metadata">
      

      

      
      <!-- Namespace Contents -->
      <div id="namespace-list-section" class="section">
        <h3 class="section-header">Namespace</h3>
        <ul class="link-list">
          
          <li><span class="type">MODULE</span> <a href="Autoinc/ClassMethods.html">Mongoid::Autoinc::ClassMethods</a></li>
          
          <li><span class="type">CLASS</span> <a href="Autoinc/Incrementor.html">Mongoid::Autoinc::Incrementor</a></li>
          
        </ul>
      </div>
      

      
      <!-- Method Quickref -->
      <div id="method-list-section" class="section">
        <h3 class="section-header">Methods</h3>
        <ul class="link-list">
          
          <li><a href="#method-i-assign-21">#assign!</a></li>
          
          <li><a href="#method-i-evaluate_scope">#evaluate_scope</a></li>
          
          <li><a href="#method-i-evaluate_step">#evaluate_step</a></li>
          
          <li><a href="#method-i-evaluate_step_proc">#evaluate_step_proc</a></li>
          
          <li><a href="#method-i-increment-21">#increment!</a></li>
          
          <li><a href="#method-i-update_auto_increments">#update_auto_increments</a></li>
          
        </ul>
      </div>
      

      
    </div>

    <div id="project-metadata">
      
      

      <div id="classindex-section" class="section project-section">
        <h3 class="section-header">Class/Module Index
          <span class="search-toggle"><img src="../images/find.png"
            height="16" width="16" alt="[+]"
            title="show/hide quicksearch" /></span></h3>
        <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
        <fieldset>
          <legend>Quicksearch</legend>
          <input type="text" name="quicksearch" value=""
            class="quicksearch-field" />
        </fieldset>
        </form>

        <ul class="link-list">
        
          <li><a href="../Mongoid.html">Mongoid</a></li>
        
          <li><a href="../Mongoid/Autoinc.html">Mongoid::Autoinc</a></li>
        
          <li><a href="../Mongoid/Autoinc/ClassMethods.html">Mongoid::Autoinc::ClassMethods</a></li>
        
          <li><a href="../Mongoid/Autoinc/Incrementor.html">Mongoid::Autoinc::Incrementor</a></li>
        
        </ul>
        <div id="no-class-search-results" style="display: none;">No matching classes.</div>
      </div>

      
    </div>
  </div>

  <div id="documentation">
    <h1 class="module">Mongoid::Autoinc</h1>

    <div id="description" class="description">
      
    </div><!-- description -->

    
    
    
    <div id="5Buntitled-5D" class="documentation-section">
      

      

      
      <!-- Constants -->
      <div id="constants-list" class="section">
        <h3 class="section-header">Constants</h3>
        <dl>
        
          <dt><a name="AlreadyAssignedError">AlreadyAssignedError</a></dt>
          
          <dd class="description"></dd>
          
        
          <dt><a name="AutoIncrementsError">AutoIncrementsError</a></dt>
          
          <dd class="description"></dd>
          
        
          <dt><a name="VERSION">VERSION</a></dt>
          
          <dd class="description"></dd>
          
        
        </dl>
      </div>
      

      

      <!-- Methods -->
      
      <div id="public-instance-method-details" class="method-section section">
        <h3 class="section-header">Public Instance Methods</h3>

      
        <div id="assign-21-method" class="method-detail ">
          <a name="method-i-assign-21"></a>

          
          <div class="method-heading">
            <span class="method-name">assign!</span><span
              class="method-args">(field)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            
            

            
            <div class="method-source-code" id="assign-21-source">
<pre>
<span class="ruby-comment"># File lib/autoinc.rb, line 32</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">assign!</span>(<span class="ruby-identifier">field</span>)
  <span class="ruby-identifier">options</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">incrementing_fields</span>[<span class="ruby-identifier">field</span>]
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">AutoIncrementsError</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:auto</span>]
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">AlreadyAssignedError</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">send</span>(<span class="ruby-identifier">field</span>).<span class="ruby-identifier">present?</span>
  <span class="ruby-identifier">increment!</span>(<span class="ruby-identifier">field</span>, <span class="ruby-identifier">options</span>)
<span class="ruby-keyword">end</span></pre>
            </div><!-- assign-21-source -->
            
          </div>

          

          
        </div><!-- assign-21-method -->

      
        <div id="evaluate_scope-method" class="method-detail ">
          <a name="method-i-evaluate_scope"></a>

          
          <div class="method-heading">
            <span class="method-name">evaluate_scope</span><span
              class="method-args">(scope)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            
            

            
            <div class="method-source-code" id="evaluate_scope-source">
<pre>
<span class="ruby-comment"># File lib/autoinc.rb, line 55</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">evaluate_scope</span>(<span class="ruby-identifier">scope</span>)
  <span class="ruby-keyword">case</span> <span class="ruby-identifier">scope</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Symbol</span> <span class="ruby-keyword">then</span> <span class="ruby-identifier">send</span>(<span class="ruby-identifier">scope</span>)
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Proc</span> <span class="ruby-keyword">then</span> <span class="ruby-identifier">instance_exec</span> &amp;<span class="ruby-identifier">scope</span>
  <span class="ruby-keyword">else</span> <span class="ruby-identifier">raise</span> <span class="ruby-string">'scope is not a Symbol or a Proc'</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- evaluate_scope-source -->
            
          </div>

          

          
        </div><!-- evaluate_scope-method -->

      
        <div id="evaluate_step-method" class="method-detail ">
          <a name="method-i-evaluate_step"></a>

          
          <div class="method-heading">
            <span class="method-name">evaluate_step</span><span
              class="method-args">(step)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            
            

            
            <div class="method-source-code" id="evaluate_step-source">
<pre>
<span class="ruby-comment"># File lib/autoinc.rb, line 63</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">evaluate_step</span>(<span class="ruby-identifier">step</span>)
  <span class="ruby-keyword">case</span> <span class="ruby-identifier">step</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Integer</span> <span class="ruby-keyword">then</span> <span class="ruby-identifier">step</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Proc</span> <span class="ruby-keyword">then</span> <span class="ruby-identifier">evaluate_step_proc</span>(<span class="ruby-identifier">step</span>)
  <span class="ruby-keyword">else</span> <span class="ruby-identifier">raise</span> <span class="ruby-string">'step is not an Integer or a Proc'</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- evaluate_step-source -->
            
          </div>

          

          
        </div><!-- evaluate_step-method -->

      
        <div id="evaluate_step_proc-method" class="method-detail ">
          <a name="method-i-evaluate_step_proc"></a>

          
          <div class="method-heading">
            <span class="method-name">evaluate_step_proc</span><span
              class="method-args">(step_proc)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            
            

            
            <div class="method-source-code" id="evaluate_step_proc-source">
<pre>
<span class="ruby-comment"># File lib/autoinc.rb, line 71</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">evaluate_step_proc</span>(<span class="ruby-identifier">step_proc</span>)
  <span class="ruby-identifier">result</span> = <span class="ruby-identifier">instance_exec</span> &amp;<span class="ruby-identifier">step_proc</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">result</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">result</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Integer</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-string">'step Proc does not evaluate to an Integer'</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- evaluate_step_proc-source -->
            
          </div>

          

          
        </div><!-- evaluate_step_proc-method -->

      
        <div id="increment-21-method" class="method-detail ">
          <a name="method-i-increment-21"></a>

          
          <div class="method-heading">
            <span class="method-name">increment!</span><span
              class="method-args">(field, options)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            
            

            
            <div class="method-source-code" id="increment-21-source">
<pre>
<span class="ruby-comment"># File lib/autoinc.rb, line 45</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">increment!</span>(<span class="ruby-identifier">field</span>, <span class="ruby-identifier">options</span>)
  <span class="ruby-identifier">options</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">dup</span>
  <span class="ruby-identifier">model_name</span> = (<span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:model_name</span>) <span class="ruby-operator">||</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">model_name</span>).<span class="ruby-identifier">to_s</span>
  <span class="ruby-identifier">options</span>[<span class="ruby-value">:scope</span>] = <span class="ruby-identifier">evaluate_scope</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value">:scope</span>]) <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:scope</span>]
  <span class="ruby-identifier">options</span>[<span class="ruby-value">:step</span>] = <span class="ruby-identifier">evaluate_step</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value">:step</span>]) <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:step</span>]
  <span class="ruby-identifier">write_attribute</span>(
      <span class="ruby-identifier">field</span>.<span class="ruby-identifier">to_sym</span>, <span class="ruby-constant">Mongoid</span><span class="ruby-operator">::</span><span class="ruby-constant">Autoinc</span><span class="ruby-operator">::</span><span class="ruby-constant">Incrementor</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">model_name</span>, <span class="ruby-identifier">field</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">inc</span>
  )
<span class="ruby-keyword">end</span></pre>
            </div><!-- increment-21-source -->
            
          </div>

          

          
        </div><!-- increment-21-method -->

      
        <div id="update_auto_increments-method" class="method-detail ">
          <a name="method-i-update_auto_increments"></a>

          
          <div class="method-heading">
            <span class="method-name">update_auto_increments</span><span
              class="method-args">()</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            
            

            
            <div class="method-source-code" id="update_auto_increments-source">
<pre>
<span class="ruby-comment"># File lib/autoinc.rb, line 39</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">update_auto_increments</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">incrementing_fields</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">field</span>, <span class="ruby-identifier">options</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">increment!</span>(<span class="ruby-identifier">field</span>, <span class="ruby-identifier">options</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:auto</span>]
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- update_auto_increments-source -->
            
          </div>

          

          
        </div><!-- update_auto_increments-method -->

      
      </div><!-- public-instance-method-details -->
    
    </div><!-- 5Buntitled-5D -->
  

  </div><!-- documentation -->

  <div id="validator-badges">
    <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
    <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
      Rdoc Generator</a> 2</small>.</p>
  </div>

</body>
</html>

